<?
	require_once('./application/models/fotoModel.php');


	class item_foto extends item_abstract
	{
		private $html;
		private $myModel;
		
		protected function init()
		{
			$this -> information['foto_id'] = '';
			$this -> information['foto_album_id'] = '';
			$this -> information['foto_path'] = '';
			$this -> information['foto_file'] = '';
			$this -> information['foto_album_naam'] = '';
			
			$this -> html = new view_htmlTag('img');
			$this -> html -> setToShortTag();
			
			$this -> myModel = fotoModel::getInstance($this -> Db);	
			
		}		
		
		
		public function getHtml(){
		
			return $this -> html;
		
		}
		
		public function render()
		{

		$this -> html -> setAttribute('alt', $this -> title);
		$this -> html -> setAttribute('src', $this -> foto_path);
		return $this -> html -> render();
	
		}
		
		public function insert()
		{
			
			$this -> myModel -> add($this);
			
		}
		public function update()
		{
			$this -> myModel -> uplFoto($this);
		}
		
		public function verwijder()
		{
			$fotoModel = new fotoModel($this -> Db);
			$fotoModel -> delFoto($this);
		}
		
		
		private function getThumbPath(){
			
			
			$pos = strrpos($this -> foto_path ,'.');
			$ext=substr($this -> foto_path,$pos,strlen($this -> foto_path));
			$name = substr($this -> foto_path,0,$pos).'_thumb';
	
			return $name.$ext;
		
		}
		
		public function renderThumb(){
		
		$this -> html -> setAttribute('alt', $this -> title);
		$this -> html -> setAttribute('src', $this -> getThumbPath());
		return $this -> html -> render();		
		}
		public function fill()
		{
			$this -> myModel -> getFotoId($this);
		}
		
	}
?>